<?php

namespace tmcore\services\crud\enum;

/**
 * 模板类型枚举
 */
class TplEnum
{
    // 列表
    const LISTS = 'lists';
    // 添加
    const ADD = 'add';
    // 编辑
    const EDIT = 'edit';
    // 删除
    const DELETE = 'delete';
    // 详情
    const DETAIL = 'detail';
    // 导出
    const EXPORT = 'export';
    // 导入
    const IMPORT = 'import';
    // 树表
    const TREE = 'treeAll';

    /**
     * 获取控制器模版
     * @param array $params
     * @return array
     */
    public static function getControllerTpl($params)
    {
        $data = [self::LISTS];

        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_detail']) || !empty($params['is_update'])) array_push($data, self::DETAIL);
        if(!empty($params['is_export'])) array_push($data, self::EXPORT);
        if(!empty($params['is_import'])) array_push($data, self::IMPORT);
        if(!empty($params['tpl_type']) && $params['tpl_type'] == CrudEnum::TPL_TYPE_TREE) array_push($data, self::TREE);

        return $data;
    }

    /**
     * 获取路由模版
     * @param array $params
     * @return array
     */
    public static function getRouteTpl($params)
    {
        $data = [self::LISTS];

        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_detail']) || !empty($params['is_update'])) array_push($data, self::DETAIL);
        if(!empty($params['is_export'])) array_push($data, self::EXPORT);
        if(!empty($params['is_import'])) array_push($data, self::IMPORT);
        if(!empty($params['tpl_type']) && $params['tpl_type'] == CrudEnum::TPL_TYPE_TREE) array_push($data, self::TREE);

        return $data;
    }

    /**
     * 获取服务类模版
     * @param array $params
     * @param bool $is_tree
     * @return array
     */
    public static function getServiceTpl($params, $is_tree = false)
    {
        $data = [];

        $data[] = $is_tree ? 'treeLists' : self::LISTS;
        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_detail']) || !empty($params['is_update'])) array_push($data, self::DETAIL);
        if(!empty($params['is_export'])) array_push($data, self::EXPORT);
        if(!empty($params['is_import'])) array_push($data, self::IMPORT);
        if(!empty($params['tpl_type']) && $params['tpl_type'] == CrudEnum::TPL_TYPE_TREE) array_push($data, self::TREE);

        return $data;
    }

    /**
     * 获取验证器模版
     * @param array $params
     * @return array
     */
    public static function getValidateTpl($params)
    {
        $data = [];

        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_detail']) || !empty($params['is_update'])) array_push($data, self::DETAIL);

        return $data;
    }

    /**
     * 获取sql模版
     * @param array $params
     * @return array
     */
    public static function getSqlTpl($params)
    {
        $data = [];

        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_detail'])) array_push($data, self::DETAIL);
        if(!empty($params['is_export'])) array_push($data, self::EXPORT);
        if(!empty($params['is_import'])) array_push($data, self::IMPORT);
        if(!empty($params['component_type']) && $params['component_type'] == 2) {
            if(!empty($params['is_insert']) || !empty($params['is_update']))array_push($data, 'editPage');
            if(!empty($params['is_detail'])) array_push($data, 'detailPage');
        }

        return $data;
    }

    /**
     * 获取vueApi模版
     * @param array $params
     * @return array
     */
    public static function getVueApiTpl($params)
    {
        $data = [self::LISTS];

        if(!empty($params['is_detail']) || !empty($params['is_update'])) array_push($data, self::DETAIL);
        if(!empty($params['is_insert'])) array_push($data, self::ADD);
        if(!empty($params['is_update'])) array_push($data, self::EDIT);
        if(!empty($params['is_delete'])) array_push($data, self::DELETE);
        if(!empty($params['is_export'])) array_push($data, self::EXPORT);
        if(!empty($params['is_import'])) array_push($data, self::IMPORT);
        if(!empty($params['tpl_type']) && $params['tpl_type'] == CrudEnum::TPL_TYPE_TREE) array_push($data, self::TREE);

        return $data;
    }
}